#include "vector.hpp"
#include <vector>
using namespace ::wk;

template <typename... Args>
void print(const Args &...args)
{
    ((std::cout << args << " "), ...);
    std::cout << "\n";
}

void test1()
{ // wk::vector<int> v1;
    std::vector<int> myvector(5);

    int *p = myvector.data();
    int *x = p;
    for (int i = 0; i < myvector.size(); i++)
        std::cout << x++ << std::endl;
    *p = 10;
    std::cout << p << std::endl;
    ++p;
    std::cout << p << std::endl;
    *p = 20;
    // 这里是以当前位置计算的偏移量
    p[2] = 100;
    std::cout << &p[2] << std::endl;
    std::cout << "myvector contains:";
    for (unsigned i = 0; i < myvector.size(); ++i)
        std::cout << ' ' << myvector[i];
    std::cout << '\n';

    std::cout << p[10] << std::endl;
}
// #define print(data) (std::cout << data << std::endl)
void test2()
{
    wk::vector<int> v1{1, 2, 3};
    wk::vector<int> v2(10, 0);
    // print(v1.capacity());
    // print(v1.size());
    // print(v1.empty());
    // print(v1.back());
    // print(v1.front());
    // for (auto &x : v1)
    //     print(x);
    // for (auto it = v1.begin(); it != v1.end(); it++)
    // {
    //     v2.push_back(*it);
    // }
    // print("size(): ", v2.size());
    // for (int i = 0; i < 10; i++)
    //     v2.push_back(i);

    // if (v2.end() == nullptr)
    //     print("v2.end() is nullptr");
    // else
    //     print("v2.end() is not nullptr");

    // print("size(): ", v2.size());

    // for (auto x : v1)
    //     print(x);
    // for (int i = 0; 1 < 4; i++)
    //     v1.push_back(i);
    // print("v1.size(): ", v1.size());
    // print(v1.back());
    // v1.pop_back();

    // print(v1.back());
    // v1.insert(v1.begin(), -1);
    // v1.insert(v1.end(), -1);
    // v1.insert(v1.begin() + 3, -1);
    // v1.insert(v1.begin() + 5, -1);
    int *p = new int[10];
    for (int i = 0; i < 10; i++)
        p[i] = rand() % (i + 1);

    for (int i = 0; i < 10; i++)
        print("p[i]: ", p[i]);
    print("=================");
    v1.insert(v1.begin(), p, p + 3);
    for (auto x : v1)
        print(x);
    print("=================");

    // v1.erase(v1.begin());
    // v1.erase(v1.begin());
    // v1.erase(v1.begin());
    // v1.erase(v1.begin());
    // v1.erase(v1.begin());
    // v1.erase(v1.begin());
    // v1.erase(v1.begin());

    // for (auto x : v1)
    //     print(x);
    v1.erase(v1.begin(), v1.end());
    print("=================");

    for (auto x : v1)
        print(x);
}
void test3()
{
    using std::vector;
    vector<int> v1;
    v1.clear();

    // vector<int> v2(10, 0);
    // vector<int> v3(15, 0);
    // vector<int> v4(32, 0);
    print(v1.capacity());
    // print(v2.capacity());
    // print(v3.capacity());
    // print(v4.capacity());
    // 二倍扩的逻辑，gcc
    for (int i = 0; i < 65; i++)
    {
        v1.push_back(i);
    }
    v1.insert(v1.begin(), 10);
    // print("v1: ", v1.capacity());
    // v1.erase(v1.begin() + 3);

    v1.erase(v1.begin(), v1.end());
    v1.resize(10);
    printf("%ld\n", v1.size());
}
int main()
{
    // test2();
    test3();
    return 0;
}